<?php
App::uses('PaymentAppModel', 'Payment.Model');
/**
 * PluginPaymentPaymentMethod Model
 *
 * @property PaymentGateway $PaymentGateway
 * @property PluginPaymentPaymentMethod $Parent
 */
class PaymentPaymentMethod extends PaymentAppModel {

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';
	
	public $useTable = 'plugin_payment_payment_methods';


	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'PaymentGateway' => array(
			'className' => 'PaymentGateway',
			'foreignKey' => 'payment_gateway_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Parent' => array(
			'className' => 'PaymentPaymentMethod',
			'foreignKey' => 'id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	public function idFromGatewayAndCode($gateway, $code){
		$data = $this->find('first', array(
				'conditions'=>array('payment_gateway_id'=>$gateway, 'gateway_code'=>$code),
				'recursive'=>-1
		));
		return $data[$this->alias]['id'];
	}
}
